package com.financing.wap.service.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.financing.wap.common.BizEnums;
import com.financing.wap.dao.IBankCardDao;
import com.financing.wap.dto.BankCardDTO;
import com.financing.wap.service.IBankCardService;
import com.financing.wap.util.Constants;
import com.financing.wap.vo.BingdingCardVO;

@Service("bankCardServiceImpl")
public class BankCardServiceImpl implements IBankCardService{

	@Autowired
	private IBankCardDao bankCardDaoImpl;

	@Override
	public List<BankCardDTO> queryBankCardList(BankCardDTO bankCardDTO)
			throws SQLException {
		return bankCardDaoImpl.queryBankCardList(bankCardDTO);
	}

	@Override
	public int updateBankCard(BankCardDTO bankCardDTO) throws SQLException {
		return bankCardDaoImpl.updateBankCard(bankCardDTO);
	}

	@Override
	public int insertBankCard(BankCardDTO bankCardDTO) throws SQLException {
		return bankCardDaoImpl.insertBankCard(bankCardDTO);
	}

	@Override
	public int deleteBankCard(BankCardDTO bankCardDTO) throws SQLException {
		return bankCardDaoImpl.deleteBankCard(bankCardDTO);
	}

	@Override
	public BankCardDTO queryBankCard(BankCardDTO bankCardDTO)
			throws SQLException {
		return bankCardDaoImpl.queryBankCard(bankCardDTO);
	}

	@Override
	public boolean checkBankType(BankCardDTO bankCardDTO) throws SQLException{
		BankCardDTO bean = new BankCardDTO();
		bean.setUserId(bankCardDTO.getUserId());
		if(Constants.BANK_CARD_TYPE_ZFB.equals(bankCardDTO.getBankType())){
			bean.setBankType("='"+Constants.BANK_CARD_TYPE_ZFB+"'");
		}else{
			bean.setBankType("!='"+Constants.BANK_CARD_TYPE_ZFB+"'");
		}
		return bankCardDaoImpl.checkBankType(bean);
	}

	@Override
	public boolean checkBankName(BankCardDTO bankCardDTO) throws SQLException {
		BankCardDTO bean = new BankCardDTO();
		bean.setUserId(bankCardDTO.getUserId());
		bean.setCardNumber(bankCardDTO.getCardNumber());
		return bankCardDaoImpl.checkBankName(bean);
	}

	@Override
	public int countOtherUserBindBankCard(Map<String, Object> map)
			throws SQLException {
		return bankCardDaoImpl.countOtherUserBindBankCard(map);
	}

	@Override
	public boolean checkBankcardAndPayplatIsBinded(String cardno, String payPlat,String userId)
			throws SQLException {
		BankCardDTO  bean = new BankCardDTO();
		bean.setCardNumber(cardno);
		bean.setPayPlat(payPlat);
		bean.setUserId(userId);
		bean.setIsDefault(BizEnums.UserEnums.USER_BINDED_CARD_DEFAULT);//处于绑定状态的银行卡
		bean = bankCardDaoImpl.queryBankCard(bean);
		return bean==null?false:true;
	}

	@Override
	public List<BingdingCardVO> queryUserBindedcardList(Map<String, Object> map)
			throws SQLException {
		return bankCardDaoImpl.queryUserBindedcardList(map);
	}



}
